import Vue from "vue";

import App from "./App.vue";
import Vuex from "vuex"; // 导入vuex
import router from "./router";

Vue.use(Vuex); // 实际执行 Vuex.install(Vue)

import { SET_COUNT, SAY, ADD } from "./mutations.js";

// const SET_COUNT = "SET_COUNT";
// const SAY = "SAY";
// const ADD = "ADD";

//全局对象
const store = new Vuex.Store({
  //data 状态
  // state:{}
  state() {
    return {
      title: "hello vuex",
      firstName: "li",
      lastName: "jack",
      num1: 100,
      num2: 200,
      count: 20,
    };
  },
  // computed
  getters: {
    g1() {
      return 100;
    },
    g2() {
      return 200;
    },
    fullName(state, getters) {
      return `${state.lastName} ${state.firstName} ${getters.g1}`;
    },
  },
  // methods 方法
  mutations: {
    SET_TITLE: (state, str = "") => {
      // setTimeout(() => {
      state.title = str;
      // }, 2000);
    },
    [SET_COUNT](state, num = 1) {
      // setTimeout(() => {
      state.count += num;
      // }, 2000);
    },
    [SAY](state) {
      console.log(state.title);
    },
    [ADD](state, arg) {
      console.log(state.num1 + state.num2 + arg);
    },
  },
  
  actions: {},
});

new Vue({
  render: (h) => h(App),
  router,
  store,
}).$mount("#app");
